package com.winning.dps.ds.service.common.impl;


import com.winning.dps.ds.dao.common.CommonApiDao;
import com.winning.dps.ds.dao.common.TokenDao;
import com.winning.dps.ds.service.common.ShiroService;
import common.entity.CommonJgUserEntity;
import common.entity.TokenEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Service
public class ShiroServiceImpl implements ShiroService {
  //  @Autowired
  //  private SysMenuDao sysMenuDao;
    @Autowired
    private CommonApiDao commonApiDao;
    @Autowired
    private TokenDao tokenDao;

    @Override
    public Set<String> getUserPermissions(String zclsh) {
        List<String> permsList;

        /*
        //系统管理员，拥有最高权限
        if(userId == Constant.SUPER_ADMIN){
            List<SysMenuEntity> menuList = sysMenuDao.queryList(new HashMap<>());
            permsList = new ArrayList<>(menuList.size());
            for(SysMenuEntity menu : menuList){
                permsList.add(menu.getPerms());
            }
        }else{
            permsList = sysUserDao.queryAllPerms(zclsh);
        }

        permsList = sysUserDao.queryAllPerms(zclsh);
        //用户权限列表
        Set<String> permsSet = new HashSet<>();
        for(String perms : permsList){
            if(StringUtils.isBlank(perms)){
                continue;
            }
            permsSet.addAll(Arrays.asList(perms.trim().split(",")));
        }

        return permsSet;
        */

        return new HashSet<>();
    }

    @Override
    public TokenEntity queryByToken(String token) {
        return tokenDao.queryByToken(token);
    }

    @Override
    public CommonJgUserEntity queryUser(String zclsh) {
        return commonApiDao.queryUserObject(zclsh);
    }
}
